package com.googlecode.cswish.struts;

import java.util.List;

import com.googlecode.cswish.util.FrameConstant;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.ParameterNameAware;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * 
 * @author Jerry.Feng 2008-12-6
 */
public class BaseActionSupport extends ActionSupport implements ParameterNameAware {

	@Override
	public boolean acceptableParameterName(String parameterName) {
		return !parameterName.startsWith(FrameConstant.PARAM_PROCTED_NAME);
	}
	
	// Reduce the duplicate key
	@Override
	public String getText(String key) {
		return super.getText(formatKey(key));
	}
	
	@Override
	public String getText(String key, String defaultValue, List args, ValueStack stack) {
		return super.getText(formatKey(key), defaultValue, args, stack);
	}
	
	private String formatKey(String key) {
		int offset = 0;
		if (key.startsWith("execute")) {
			offset = "execute".length();
			if (key.startsWith(".data", offset)) {
				offset += ".data".length();
			}
		}
		if (offset > 0) {
			key = "model" + key.substring(offset);
		}
		return key;
	}
}